<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>Document</title>
	</head>
	<body>
		<div id="time"></div>
		<script>
			//计算现在到明年09-01的时间差, 然后开始倒计时,并输出在页面上, 输出格式: x天x小时x分钟x秒。
			function timer() {
				let nowTime = new Date();
				let future = new Date("2022-09-01");
				let time = future - nowTime;
				let day = Math.floor(time / (24 * 3600 * 1000)); //347
				//计算天数后剩余的毫秒数
				let leave = time % (24 * 3600 * 1000); // 
				let hours = Math.floor(leave / (60 * 60 * 1000));
				//计算小时后剩余的毫秒数
				let leave2 = leave % (3600 * 1000);
				let minutes = Math.floor(leave2 / (60 * 1000));
				//计算分钟后剩余的毫秒数
				let leave3 = leave2 % (60 * 1000);
				let second = Math.floor(leave3 / 1000);
				document.getElementById('time').innerHTML = day + "天" + hours + "小时" + minutes + "分钟" + second + "秒";

			}

			setInterval("timer()", 1000);
		</script>
	</body>
</html>
